
<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.base }}style/license.css?v={{ layui.admin.v }}-1" media="all">
</script>
<!-- nav部分 -->
<div class="page">
<div class="layui-header header" winter>
  <!-- 公司logo -->
  <a class="logo layui-hide-xs" href="/index.html" id="siteLogo"></a>
  <ul class="layui-nav xxpay-nav layui-hide-xs" lay-filter="xxpay_nav">
    <li class="layui-nav-item"><a href="/index.html"><button class="layui-btn mch-login">官网</button></a></li>
  </ul>

  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <div  class="login-text">官方授权</div>
      <p class="siteTitle layui-hide-xs"></p>
    </div>
    <form>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layadmin-user-login-box-bg">
          <div class="layui-form-item">
            <label class="layui-form-label">授权用户</label>
            <input type="text" id="subject" readonly class="layui-input">
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">授权截止</label>
            <input type="text" id="after" readonly class="layui-input">
          </div>
          <div class="layui-form-item layui-hide licenseCheck">
            <label class="layui-form-label">授权信息</label>
            <textarea style="height: 200px" type="text" name="licenseCheck" id="LAY-licenseCheck" readonly class="layui-textarea"></textarea>
          </div>
          <input type="file" id="file" class="layui-hide fileTypeInput" />
          <div class="layui-form-item">
            <div style="margin-left: 25%;">
              <a class="layui-btn layui-btn-sm layui-btn-normal" id="LAY-get-licenseCheck"><i class="layui-icon layui-icon-list"></i>获取校验信息</a>
            </div>
            <div style="margin-left: 5%;">
              <a class="layui-btn  layui-btn-sm layui-btn-normal" id="LAY-upload" onclick="layui.$('#file').click()">
                <i class="layui-icon layui-icon-upload"></i><span id="fileText">上传授权文件</span>
              </a>
            </div>
          </div>

          <div class="layui-form-item" style="line-height: 25px;">
            系统授权步骤：<br/>
            1. 点击获取校验信息，将生成的字符串发给官方技术；<br/>
            2. 技术人员确认后，为您生成一个.lic后缀的授权文件；<br/>
            3. 点击上传授权文件，上传后系统会自动安装并更新授权；
          </div>
        </div>
      </div>
    </form>
  </div>
</div>
<div style="height: 100px"></div>
</div>
<!-- footer部分 -->
<div class="footer layui-hide-xs">
  <div class="div-line"></div>
  <div class="footer-pallet">
    <div class="copyright" id="copyRight"></div>
    <div class="links-box">
      <p id="serviceTel"></p>
      <p id="serviceQQ" style="margin-right: 30px"></p>
      <a href="">关于我们</a>
      <a href="">开发文档</a>
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form', 'user'], function(){
  var $ = layui.$
  ,setter = layui.setter
  ,admin = layui.admin
  ,form = layui.form
  ,router = layui.router()
  ,search = router.search;

  //变更网站标题
  $.ajax({
    async: false, type: 'get',
    url: layui.setter.baseUrl + '/auth/siteTitle',
    success: function(res){
      $("#siteLogo").append('<img src="'+res.data.siteLogo+'" style="height: 30px;" alt="'+res.data.siteTitle+'">');
      $("#copyRight").text(res.data.copyRight);
      $("#serviceTel").append(res.data.serviceTel);
      $("#serviceQQ").attr("href", 'http://wpa.qq.com/msgrd?v=3&uin='+res.data.serviceQQ+'&site=qq&menu=yes').append(res.data.serviceQQ);
    }
  });

  $.ajax({
      async: false, type: 'get',
      url: layui.setter.baseUrl + '/license/getLicInfo',
      success: function (res) {
          $("#subject").val(res.data.subject);
          $("#after").val(res.data.after);
      }
  });

  $('body').off('click', "#LAY-get-licenseCheck").on('click', "#LAY-get-licenseCheck", function(){
      var loadingIndex = layer.load(1);
      $.ajax({
          type: 'get',
          url: layui.setter.baseUrl + '/license/getServerInfos',
          data: {},
          success: function(res){
              layer.close(loadingIndex);
              var content = JSON.stringify(res, null, 4);
              $(".licenseCheck").removeClass("layui-hide");
              $("#LAY-licenseCheck").val(content);
              $("#LAY-licenseCheck").select();
          }
      });
  });

  $('.fileTypeInput').change(function(){
      var formdata = new FormData(); //封装form参数

      $.each($('input[type="file"]'), function(){ //附件信息
          if($(this).val()){
              formdata.append($(this).attr('id'), $(this)[0].files[0]);
          }
      });
      layer.prompt({title: '请输入超级密码', formType: 1}, function(pass, proId) {
          formdata.append("password", pass);
          //这里可以写ajax方法提交表单
          admin.req({
              type: "POST",
              url: layui.setter.baseUrl + '/license/uploadLicense',
              data: formdata,
              processData: false,   //设置为false。因为data值是FormData对象，不需要对数据做处理。
              contentType: false,  //设置为false，不设置contentType值，因为是由<form>表单构造的FormData对象，且已经声明了属性enctype="multipart/form-data"，所以这里设置为false。
              success: function (res) {
                  if (res.code == 0) {
                      layer.closeAll(); //关闭所有弹层
                      layer.msg("操作成功", {icon:1,time:1000},function(){
                          setTimeout('window.location.reload()',1000);
                      });
                  }
              }
          });
      });
  });

    form.render();

});
</script>